﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using GPSTrackingDBV2.Entities;
using GPSTrackingDBV2.Data;

#endregion

namespace GPSTrackingDBV2.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="AdministratorsProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class AdministratorsProviderBaseCore : EntityProviderBase<GPSTrackingDBV2.Entities.Administrators, GPSTrackingDBV2.Entities.AdministratorsKey>
	{		
		#region Get from Many To Many Relationship Functions
		#region GetByDepartmentIdFromAdministratorsByDepartments
		
		/// <summary>
		///		Gets Administrators objects from the datasource by DepartmentID in the
		///		AdministratorsByDepartments table. Table Administrators is related to table Departments
		///		through the (M:N) relationship defined in the AdministratorsByDepartments table.
		/// </summary>
		/// <param name="_departmentId"></param>
		/// <returns>Returns a typed collection of Administrators objects.</returns>
		public TList<Administrators> GetByDepartmentIdFromAdministratorsByDepartments(System.Int32 _departmentId)
		{
			int count = -1;
			return GetByDepartmentIdFromAdministratorsByDepartments(null,_departmentId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.Administrators objects from the datasource by DepartmentID in the
		///		AdministratorsByDepartments table. Table Administrators is related to table Departments
		///		through the (M:N) relationship defined in the AdministratorsByDepartments table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_departmentId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Administrators objects.</returns>
		public TList<Administrators> GetByDepartmentIdFromAdministratorsByDepartments(System.Int32 _departmentId, int start, int pageLength)
		{
			int count = -1;
			return GetByDepartmentIdFromAdministratorsByDepartments(null, _departmentId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Administrators objects from the datasource by DepartmentID in the
		///		AdministratorsByDepartments table. Table Administrators is related to table Departments
		///		through the (M:N) relationship defined in the AdministratorsByDepartments table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_departmentId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Administrators objects.</returns>
		public TList<Administrators> GetByDepartmentIdFromAdministratorsByDepartments(TransactionManager transactionManager, System.Int32 _departmentId)
		{
			int count = -1;
			return GetByDepartmentIdFromAdministratorsByDepartments(transactionManager, _departmentId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets Administrators objects from the datasource by DepartmentID in the
		///		AdministratorsByDepartments table. Table Administrators is related to table Departments
		///		through the (M:N) relationship defined in the AdministratorsByDepartments table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_departmentId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Administrators objects.</returns>
		public TList<Administrators> GetByDepartmentIdFromAdministratorsByDepartments(TransactionManager transactionManager, System.Int32 _departmentId,int start, int pageLength)
		{
			int count = -1;
			return GetByDepartmentIdFromAdministratorsByDepartments(transactionManager, _departmentId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Administrators objects from the datasource by DepartmentID in the
		///		AdministratorsByDepartments table. Table Administrators is related to table Departments
		///		through the (M:N) relationship defined in the AdministratorsByDepartments table.
		/// </summary>
		/// <param name="_departmentId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Administrators objects.</returns>
		public TList<Administrators> GetByDepartmentIdFromAdministratorsByDepartments(System.Int32 _departmentId,int start, int pageLength, out int count)
		{
			
			return GetByDepartmentIdFromAdministratorsByDepartments(null, _departmentId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets Administrators objects from the datasource by DepartmentID in the
		///		AdministratorsByDepartments table. Table Administrators is related to table Departments
		///		through the (M:N) relationship defined in the AdministratorsByDepartments table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_departmentId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Administrators objects.</returns>
		public abstract TList<Administrators> GetByDepartmentIdFromAdministratorsByDepartments(TransactionManager transactionManager,System.Int32 _departmentId, int start, int pageLength, out int count);
		
		#endregion GetByDepartmentIdFromAdministratorsByDepartments
		
		#region GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator
		
		/// <summary>
		///		Gets Administrators objects from the datasource by CompanyID in the
		///		AdministratorsRolesByAdministrator table. Table Administrators is related to table CompaniesByAdministratorsRoles
		///		through the (M:N) relationship defined in the AdministratorsRolesByAdministrator table.
		/// </summary>
		/// <param name="_companyId"></param>
		/// <param name="_administratorRoleId"></param>
		/// <returns>Returns a typed collection of Administrators objects.</returns>
		public TList<Administrators> GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(System.Int32 _companyId, System.Int32 _administratorRoleId)
		{
			int count = -1;
			return GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(null,_companyId, _administratorRoleId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.Administrators objects from the datasource by CompanyID in the
		///		AdministratorsRolesByAdministrator table. Table Administrators is related to table CompaniesByAdministratorsRoles
		///		through the (M:N) relationship defined in the AdministratorsRolesByAdministrator table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_companyId"></param>
		/// <param name="_administratorRoleId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Administrators objects.</returns>
		public TList<Administrators> GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(System.Int32 _companyId, System.Int32 _administratorRoleId, int start, int pageLength)
		{
			int count = -1;
			return GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(null, _companyId, _administratorRoleId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Administrators objects from the datasource by CompanyID in the
		///		AdministratorsRolesByAdministrator table. Table Administrators is related to table CompaniesByAdministratorsRoles
		///		through the (M:N) relationship defined in the AdministratorsRolesByAdministrator table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <param name="_administratorRoleId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Administrators objects.</returns>
		public TList<Administrators> GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(TransactionManager transactionManager, System.Int32 _companyId, System.Int32 _administratorRoleId)
		{
			int count = -1;
			return GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(transactionManager, _companyId, _administratorRoleId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets Administrators objects from the datasource by CompanyID in the
		///		AdministratorsRolesByAdministrator table. Table Administrators is related to table CompaniesByAdministratorsRoles
		///		through the (M:N) relationship defined in the AdministratorsRolesByAdministrator table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <param name="_administratorRoleId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Administrators objects.</returns>
		public TList<Administrators> GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(TransactionManager transactionManager, System.Int32 _companyId, System.Int32 _administratorRoleId,int start, int pageLength)
		{
			int count = -1;
			return GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(transactionManager, _companyId, _administratorRoleId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Administrators objects from the datasource by CompanyID in the
		///		AdministratorsRolesByAdministrator table. Table Administrators is related to table CompaniesByAdministratorsRoles
		///		through the (M:N) relationship defined in the AdministratorsRolesByAdministrator table.
		/// </summary>
		/// <param name="_companyId"></param>
		/// <param name="_administratorRoleId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Administrators objects.</returns>
		public TList<Administrators> GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(System.Int32 _companyId, System.Int32 _administratorRoleId,int start, int pageLength, out int count)
		{
			
			return GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(null, _companyId, _administratorRoleId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets Administrators objects from the datasource by CompanyID in the
		///		AdministratorsRolesByAdministrator table. Table Administrators is related to table CompaniesByAdministratorsRoles
		///		through the (M:N) relationship defined in the AdministratorsRolesByAdministrator table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_companyId"></param>
		/// <param name="_administratorRoleId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Administrators objects.</returns>
		public abstract TList<Administrators> GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator(TransactionManager transactionManager,System.Int32 _companyId, System.Int32 _administratorRoleId, int start, int pageLength, out int count);
		
		#endregion GetByCompanyIdAdministratorRoleIdFromAdministratorsRolesByAdministrator
		
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, GPSTrackingDBV2.Entities.AdministratorsKey key)
		{
			return Delete(transactionManager, key.AdminUsername, key.CompanyId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_adminUsername">. Primary Key.</param>
		/// <param name="_companyId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.String _adminUsername, System.Int32 _companyId)
		{
			return Delete(null, _adminUsername, _companyId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername">. Primary Key.</param>
		/// <param name="_companyId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Administrators_Companies key.
		///		FK_Administrators_Companies Description: 
		/// </summary>
		/// <param name="_companyId"></param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.Administrators objects.</returns>
		public TList<Administrators> GetByCompanyId(System.Int32 _companyId)
		{
			int count = -1;
			return GetByCompanyId(_companyId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Administrators_Companies key.
		///		FK_Administrators_Companies Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.Administrators objects.</returns>
		/// <remarks></remarks>
		public TList<Administrators> GetByCompanyId(TransactionManager transactionManager, System.Int32 _companyId)
		{
			int count = -1;
			return GetByCompanyId(transactionManager, _companyId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_Administrators_Companies key.
		///		FK_Administrators_Companies Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.Administrators objects.</returns>
		public TList<Administrators> GetByCompanyId(TransactionManager transactionManager, System.Int32 _companyId, int start, int pageLength)
		{
			int count = -1;
			return GetByCompanyId(transactionManager, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Administrators_Companies key.
		///		fkAdministratorsCompanies Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.Administrators objects.</returns>
		public TList<Administrators> GetByCompanyId(System.Int32 _companyId, int start, int pageLength)
		{
			int count =  -1;
			return GetByCompanyId(null, _companyId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Administrators_Companies key.
		///		fkAdministratorsCompanies Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_companyId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.Administrators objects.</returns>
		public TList<Administrators> GetByCompanyId(System.Int32 _companyId, int start, int pageLength,out int count)
		{
			return GetByCompanyId(null, _companyId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Administrators_Companies key.
		///		FK_Administrators_Companies Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.Administrators objects.</returns>
		public abstract TList<Administrators> GetByCompanyId(TransactionManager transactionManager, System.Int32 _companyId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override GPSTrackingDBV2.Entities.Administrators Get(TransactionManager transactionManager, GPSTrackingDBV2.Entities.AdministratorsKey key, int start, int pageLength)
		{
			return GetByAdminUsernameCompanyId(transactionManager, key.AdminUsername, key.CompanyId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_Administrators_1 index.
		/// </summary>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.Administrators"/> class.</returns>
		public GPSTrackingDBV2.Entities.Administrators GetByAdminUsernameCompanyId(System.String _adminUsername, System.Int32 _companyId)
		{
			int count = -1;
			return GetByAdminUsernameCompanyId(null,_adminUsername, _companyId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Administrators_1 index.
		/// </summary>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.Administrators"/> class.</returns>
		public GPSTrackingDBV2.Entities.Administrators GetByAdminUsernameCompanyId(System.String _adminUsername, System.Int32 _companyId, int start, int pageLength)
		{
			int count = -1;
			return GetByAdminUsernameCompanyId(null, _adminUsername, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Administrators_1 index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.Administrators"/> class.</returns>
		public GPSTrackingDBV2.Entities.Administrators GetByAdminUsernameCompanyId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId)
		{
			int count = -1;
			return GetByAdminUsernameCompanyId(transactionManager, _adminUsername, _companyId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Administrators_1 index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.Administrators"/> class.</returns>
		public GPSTrackingDBV2.Entities.Administrators GetByAdminUsernameCompanyId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId, int start, int pageLength)
		{
			int count = -1;
			return GetByAdminUsernameCompanyId(transactionManager, _adminUsername, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Administrators_1 index.
		/// </summary>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.Administrators"/> class.</returns>
		public GPSTrackingDBV2.Entities.Administrators GetByAdminUsernameCompanyId(System.String _adminUsername, System.Int32 _companyId, int start, int pageLength, out int count)
		{
			return GetByAdminUsernameCompanyId(null, _adminUsername, _companyId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Administrators_1 index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.Administrators"/> class.</returns>
		public abstract GPSTrackingDBV2.Entities.Administrators GetByAdminUsernameCompanyId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;Administrators&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;Administrators&gt;"/></returns>
		public static TList<Administrators> Fill(IDataReader reader, TList<Administrators> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				GPSTrackingDBV2.Entities.Administrators c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("Administrators")
					.Append("|").Append((System.String)reader[((int)AdministratorsColumn.AdminUsername - 1)])
					.Append("|").Append((System.Int32)reader[((int)AdministratorsColumn.CompanyId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<Administrators>(
					key.ToString(), // EntityTrackingKey
					"Administrators",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new GPSTrackingDBV2.Entities.Administrators();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.AdminUsername = (System.String)reader[((int)AdministratorsColumn.AdminUsername - 1)];
					c.OriginalAdminUsername = c.AdminUsername;
					c.CompanyId = (System.Int32)reader[((int)AdministratorsColumn.CompanyId - 1)];
					c.OriginalCompanyId = c.CompanyId;
					c.Password = (System.String)reader[((int)AdministratorsColumn.Password - 1)];
					c.Identification = (reader.IsDBNull(((int)AdministratorsColumn.Identification - 1)))?null:(System.String)reader[((int)AdministratorsColumn.Identification - 1)];
					c.Name = (System.String)reader[((int)AdministratorsColumn.Name - 1)];
					c.FirstName = (System.String)reader[((int)AdministratorsColumn.FirstName - 1)];
					c.LastName = (System.String)reader[((int)AdministratorsColumn.LastName - 1)];
					c.CountryId = (System.Int32)reader[((int)AdministratorsColumn.CountryId - 1)];
					c.StateId = (System.Int32)reader[((int)AdministratorsColumn.StateId - 1)];
					c.CityId = (System.Int32)reader[((int)AdministratorsColumn.CityId - 1)];
					c.Mobile = (reader.IsDBNull(((int)AdministratorsColumn.Mobile - 1)))?null:(System.String)reader[((int)AdministratorsColumn.Mobile - 1)];
					c.Phone = (reader.IsDBNull(((int)AdministratorsColumn.Phone - 1)))?null:(System.String)reader[((int)AdministratorsColumn.Phone - 1)];
					c.IsActive = (System.Boolean)reader[((int)AdministratorsColumn.IsActive - 1)];
					c.CreationDate = (System.DateTime)reader[((int)AdministratorsColumn.CreationDate - 1)];
					c.Email = (reader.IsDBNull(((int)AdministratorsColumn.Email - 1)))?null:(System.String)reader[((int)AdministratorsColumn.Email - 1)];
					c.LastTick = (reader.IsDBNull(((int)AdministratorsColumn.LastTick - 1)))?null:(System.Int64?)reader[((int)AdministratorsColumn.LastTick - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingDBV2.Entities.Administrators"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.Administrators"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, GPSTrackingDBV2.Entities.Administrators entity)
		{
			if (!reader.Read()) return;
			
			entity.AdminUsername = (System.String)reader[((int)AdministratorsColumn.AdminUsername - 1)];
			entity.OriginalAdminUsername = (System.String)reader["AdminUsername"];
			entity.CompanyId = (System.Int32)reader[((int)AdministratorsColumn.CompanyId - 1)];
			entity.OriginalCompanyId = (System.Int32)reader["CompanyID"];
			entity.Password = (System.String)reader[((int)AdministratorsColumn.Password - 1)];
			entity.Identification = (reader.IsDBNull(((int)AdministratorsColumn.Identification - 1)))?null:(System.String)reader[((int)AdministratorsColumn.Identification - 1)];
			entity.Name = (System.String)reader[((int)AdministratorsColumn.Name - 1)];
			entity.FirstName = (System.String)reader[((int)AdministratorsColumn.FirstName - 1)];
			entity.LastName = (System.String)reader[((int)AdministratorsColumn.LastName - 1)];
			entity.CountryId = (System.Int32)reader[((int)AdministratorsColumn.CountryId - 1)];
			entity.StateId = (System.Int32)reader[((int)AdministratorsColumn.StateId - 1)];
			entity.CityId = (System.Int32)reader[((int)AdministratorsColumn.CityId - 1)];
			entity.Mobile = (reader.IsDBNull(((int)AdministratorsColumn.Mobile - 1)))?null:(System.String)reader[((int)AdministratorsColumn.Mobile - 1)];
			entity.Phone = (reader.IsDBNull(((int)AdministratorsColumn.Phone - 1)))?null:(System.String)reader[((int)AdministratorsColumn.Phone - 1)];
			entity.IsActive = (System.Boolean)reader[((int)AdministratorsColumn.IsActive - 1)];
			entity.CreationDate = (System.DateTime)reader[((int)AdministratorsColumn.CreationDate - 1)];
			entity.Email = (reader.IsDBNull(((int)AdministratorsColumn.Email - 1)))?null:(System.String)reader[((int)AdministratorsColumn.Email - 1)];
			entity.LastTick = (reader.IsDBNull(((int)AdministratorsColumn.LastTick - 1)))?null:(System.Int64?)reader[((int)AdministratorsColumn.LastTick - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingDBV2.Entities.Administrators"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.Administrators"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, GPSTrackingDBV2.Entities.Administrators entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.AdminUsername = (System.String)dataRow["AdminUsername"];
			entity.OriginalAdminUsername = (System.String)dataRow["AdminUsername"];
			entity.CompanyId = (System.Int32)dataRow["CompanyID"];
			entity.OriginalCompanyId = (System.Int32)dataRow["CompanyID"];
			entity.Password = (System.String)dataRow["Password"];
			entity.Identification = Convert.IsDBNull(dataRow["Identification"]) ? null : (System.String)dataRow["Identification"];
			entity.Name = (System.String)dataRow["Name"];
			entity.FirstName = (System.String)dataRow["FirstName"];
			entity.LastName = (System.String)dataRow["LastName"];
			entity.CountryId = (System.Int32)dataRow["CountryID"];
			entity.StateId = (System.Int32)dataRow["StateID"];
			entity.CityId = (System.Int32)dataRow["CityID"];
			entity.Mobile = Convert.IsDBNull(dataRow["Mobile"]) ? null : (System.String)dataRow["Mobile"];
			entity.Phone = Convert.IsDBNull(dataRow["Phone"]) ? null : (System.String)dataRow["Phone"];
			entity.IsActive = (System.Boolean)dataRow["IsActive"];
			entity.CreationDate = (System.DateTime)dataRow["CreationDate"];
			entity.Email = Convert.IsDBNull(dataRow["Email"]) ? null : (System.String)dataRow["Email"];
			entity.LastTick = Convert.IsDBNull(dataRow["LastTick"]) ? null : (System.Int64?)dataRow["LastTick"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.Administrators"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">GPSTrackingDBV2.Entities.Administrators Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, GPSTrackingDBV2.Entities.Administrators entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region CompanyIdSource	
			if (CanDeepLoad(entity, "Companies|CompanyIdSource", deepLoadType, innerList) 
				&& entity.CompanyIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.CompanyId;
				Companies tmpEntity = EntityManager.LocateEntity<Companies>(EntityLocator.ConstructKeyFromPkItems(typeof(Companies), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.CompanyIdSource = tmpEntity;
				else
					entity.CompanyIdSource = DataRepository.CompaniesProvider.GetByCompanyId(transactionManager, entity.CompanyId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CompanyIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CompanyIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.CompaniesProvider.DeepLoad(transactionManager, entity.CompanyIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion CompanyIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByAdminUsernameCompanyId methods when available
			
			#region AdministratorsByDepartmentsCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<AdministratorsByDepartments>|AdministratorsByDepartmentsCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'AdministratorsByDepartmentsCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.AdministratorsByDepartmentsCollection = DataRepository.AdministratorsByDepartmentsProvider.GetByAdminUsernameCompanyId(transactionManager, entity.AdminUsername, entity.CompanyId);

				if (deep && entity.AdministratorsByDepartmentsCollection.Count > 0)
				{
					deepHandles.Add("AdministratorsByDepartmentsCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<AdministratorsByDepartments>) DataRepository.AdministratorsByDepartmentsProvider.DeepLoad,
						new object[] { transactionManager, entity.AdministratorsByDepartmentsCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<Departments>|DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments", deepLoadType, innerList))
			{
				entity.DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments = DataRepository.DepartmentsProvider.GetByAdminUsernameCompanyIdFromAdministratorsByDepartments(transactionManager, entity.AdminUsername, entity.CompanyId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments != null)
				{
					deepHandles.Add("DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< Departments >) DataRepository.DepartmentsProvider.DeepLoad,
						new object[] { transactionManager, entity.DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region AdministratorsByEmailCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<AdministratorsByEmail>|AdministratorsByEmailCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'AdministratorsByEmailCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.AdministratorsByEmailCollection = DataRepository.AdministratorsByEmailProvider.GetByAdminUsernameCompanyId(transactionManager, entity.AdminUsername, entity.CompanyId);

				if (deep && entity.AdministratorsByEmailCollection.Count > 0)
				{
					deepHandles.Add("AdministratorsByEmailCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<AdministratorsByEmail>) DataRepository.AdministratorsByEmailProvider.DeepLoad,
						new object[] { transactionManager, entity.AdministratorsByEmailCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region AdministratorsRolesByAdministratorCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<AdministratorsRolesByAdministrator>|AdministratorsRolesByAdministratorCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'AdministratorsRolesByAdministratorCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.AdministratorsRolesByAdministratorCollection = DataRepository.AdministratorsRolesByAdministratorProvider.GetByAdminUsernameCompanyId(transactionManager, entity.AdminUsername, entity.CompanyId);

				if (deep && entity.AdministratorsRolesByAdministratorCollection.Count > 0)
				{
					deepHandles.Add("AdministratorsRolesByAdministratorCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<AdministratorsRolesByAdministrator>) DataRepository.AdministratorsRolesByAdministratorProvider.DeepLoad,
						new object[] { transactionManager, entity.AdministratorsRolesByAdministratorCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<CompaniesByAdministratorsRoles>|CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator", deepLoadType, innerList))
			{
				entity.CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator = DataRepository.CompaniesByAdministratorsRolesProvider.GetByAdminUsernameCompanyIdFromAdministratorsRolesByAdministrator(transactionManager, entity.AdminUsername, entity.CompanyId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator != null)
				{
					deepHandles.Add("CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< CompaniesByAdministratorsRoles >) DataRepository.CompaniesByAdministratorsRolesProvider.DeepLoad,
						new object[] { transactionManager, entity.CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the GPSTrackingDBV2.Entities.Administrators object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">GPSTrackingDBV2.Entities.Administrators instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">GPSTrackingDBV2.Entities.Administrators Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, GPSTrackingDBV2.Entities.Administrators entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region CompanyIdSource
			if (CanDeepSave(entity, "Companies|CompanyIdSource", deepSaveType, innerList) 
				&& entity.CompanyIdSource != null)
			{
				DataRepository.CompaniesProvider.Save(transactionManager, entity.CompanyIdSource);
				entity.CompanyId = entity.CompanyIdSource.CompanyId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();

			#region DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments>
			if (CanDeepSave(entity.DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments, "List<Departments>|DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments", deepSaveType, innerList))
			{
				if (entity.DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments.Count > 0 || entity.DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments.DeletedItems.Count > 0)
				{
					DataRepository.DepartmentsProvider.Save(transactionManager, entity.DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments); 
					deepHandles.Add("DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<Departments>) DataRepository.DepartmentsProvider.DeepSave,
						new object[] { transactionManager, entity.DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator>
			if (CanDeepSave(entity.CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator, "List<CompaniesByAdministratorsRoles>|CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator", deepSaveType, innerList))
			{
				if (entity.CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator.Count > 0 || entity.CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator.DeletedItems.Count > 0)
				{
					DataRepository.CompaniesByAdministratorsRolesProvider.Save(transactionManager, entity.CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator); 
					deepHandles.Add("CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<CompaniesByAdministratorsRoles>) DataRepository.CompaniesByAdministratorsRolesProvider.DeepSave,
						new object[] { transactionManager, entity.CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 
	
			#region List<AdministratorsByDepartments>
				if (CanDeepSave(entity.AdministratorsByDepartmentsCollection, "List<AdministratorsByDepartments>|AdministratorsByDepartmentsCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(AdministratorsByDepartments child in entity.AdministratorsByDepartmentsCollection)
					{
						if(child.AdminUsernameCompanyIdSource != null)
						{
								child.AdminUsername = child.AdminUsernameCompanyIdSource.AdminUsername;
								child.CompanyId = child.AdminUsernameCompanyIdSource.CompanyId;
						}

						if(child.DepartmentIdSource != null)
						{
								child.DepartmentId = child.DepartmentIdSource.DepartmentId;
						}

					}

					if (entity.AdministratorsByDepartmentsCollection.Count > 0 || entity.AdministratorsByDepartmentsCollection.DeletedItems.Count > 0)
					{
						//DataRepository.AdministratorsByDepartmentsProvider.Save(transactionManager, entity.AdministratorsByDepartmentsCollection);
						
						deepHandles.Add("AdministratorsByDepartmentsCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< AdministratorsByDepartments >) DataRepository.AdministratorsByDepartmentsProvider.DeepSave,
							new object[] { transactionManager, entity.AdministratorsByDepartmentsCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<AdministratorsByEmail>
				if (CanDeepSave(entity.AdministratorsByEmailCollection, "List<AdministratorsByEmail>|AdministratorsByEmailCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(AdministratorsByEmail child in entity.AdministratorsByEmailCollection)
					{
						if(child.AdminUsernameCompanyIdSource != null)
						{
							child.AdminUsername = child.AdminUsernameCompanyIdSource.AdminUsername;
							child.CompanyId = child.AdminUsernameCompanyIdSource.CompanyId;
						}
						else
						{
							child.AdminUsername = entity.AdminUsername;
							child.CompanyId = entity.CompanyId;
						}

					}

					if (entity.AdministratorsByEmailCollection.Count > 0 || entity.AdministratorsByEmailCollection.DeletedItems.Count > 0)
					{
						//DataRepository.AdministratorsByEmailProvider.Save(transactionManager, entity.AdministratorsByEmailCollection);
						
						deepHandles.Add("AdministratorsByEmailCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< AdministratorsByEmail >) DataRepository.AdministratorsByEmailProvider.DeepSave,
							new object[] { transactionManager, entity.AdministratorsByEmailCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<AdministratorsRolesByAdministrator>
				if (CanDeepSave(entity.AdministratorsRolesByAdministratorCollection, "List<AdministratorsRolesByAdministrator>|AdministratorsRolesByAdministratorCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(AdministratorsRolesByAdministrator child in entity.AdministratorsRolesByAdministratorCollection)
					{
						if(child.AdminUsernameCompanyIdSource != null)
						{
								child.AdminUsername = child.AdminUsernameCompanyIdSource.AdminUsername;
								child.CompanyId = child.AdminUsernameCompanyIdSource.CompanyId;
						}

						if(child.CompanyIdAdministratorRoleIdSource != null)
						{
								child.CompanyId = child.CompanyIdAdministratorRoleIdSource.CompanyId;
								child.AdministratorRoleId = child.CompanyIdAdministratorRoleIdSource.AdministratorRoleId;
						}

					}

					if (entity.AdministratorsRolesByAdministratorCollection.Count > 0 || entity.AdministratorsRolesByAdministratorCollection.DeletedItems.Count > 0)
					{
						//DataRepository.AdministratorsRolesByAdministratorProvider.Save(transactionManager, entity.AdministratorsRolesByAdministratorCollection);
						
						deepHandles.Add("AdministratorsRolesByAdministratorCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< AdministratorsRolesByAdministrator >) DataRepository.AdministratorsRolesByAdministratorProvider.DeepSave,
							new object[] { transactionManager, entity.AdministratorsRolesByAdministratorCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region AdministratorsChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>GPSTrackingDBV2.Entities.Administrators</c>
	///</summary>
	public enum AdministratorsChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Companies</c> at CompanyIdSource
		///</summary>
		[ChildEntityType(typeof(Companies))]
		Companies,
	
		///<summary>
		/// Collection of <c>Administrators</c> as OneToMany for AdministratorsByDepartmentsCollection
		///</summary>
		[ChildEntityType(typeof(TList<AdministratorsByDepartments>))]
		AdministratorsByDepartmentsCollection,

		///<summary>
		/// Collection of <c>Administrators</c> as ManyToMany for DepartmentsCollection_From_AdministratorsByDepartments
		///</summary>
		[ChildEntityType(typeof(TList<Departments>))]
		DepartmentIdDepartmentsCollection_From_AdministratorsByDepartments,

		///<summary>
		/// Collection of <c>Administrators</c> as OneToMany for AdministratorsByEmailCollection
		///</summary>
		[ChildEntityType(typeof(TList<AdministratorsByEmail>))]
		AdministratorsByEmailCollection,

		///<summary>
		/// Collection of <c>Administrators</c> as OneToMany for AdministratorsRolesByAdministratorCollection
		///</summary>
		[ChildEntityType(typeof(TList<AdministratorsRolesByAdministrator>))]
		AdministratorsRolesByAdministratorCollection,

		///<summary>
		/// Collection of <c>Administrators</c> as ManyToMany for CompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator
		///</summary>
		[ChildEntityType(typeof(TList<CompaniesByAdministratorsRoles>))]
		CompanyIdAdministratorRoleIdCompaniesByAdministratorsRolesCollection_From_AdministratorsRolesByAdministrator,
	}
	
	#endregion AdministratorsChildEntityTypes
	
	#region AdministratorsFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;AdministratorsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Administrators"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class AdministratorsFilterBuilder : SqlFilterBuilder<AdministratorsColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AdministratorsFilterBuilder class.
		/// </summary>
		public AdministratorsFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the AdministratorsFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public AdministratorsFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the AdministratorsFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public AdministratorsFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion AdministratorsFilterBuilder
	
	#region AdministratorsParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;AdministratorsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Administrators"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class AdministratorsParameterBuilder : ParameterizedSqlFilterBuilder<AdministratorsColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AdministratorsParameterBuilder class.
		/// </summary>
		public AdministratorsParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the AdministratorsParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public AdministratorsParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the AdministratorsParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public AdministratorsParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion AdministratorsParameterBuilder
	
	#region AdministratorsSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;AdministratorsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Administrators"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class AdministratorsSortBuilder : SqlSortBuilder<AdministratorsColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AdministratorsSqlSortBuilder class.
		/// </summary>
		public AdministratorsSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion AdministratorsSortBuilder
	
} // end namespace
